/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Locale;

/**
 * <p>Project: app2022 - Javacj
 * <p>Powered by webrx On 2022-01-18 10:06:53
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Javacj {
    //统计Java文件多少行
    public static long rows = 0;
    public static long filecount = 0;

    public static void main(String[] args) {
        count(new File("C:\\app2022"));
        System.out.println(rows);
        System.out.println(filecount);
    }

    public static void count(File file) {
        if (file.isDirectory()) {
            for (File t : file.listFiles()) {
                if (t.isDirectory()) {
                    count(t);
                } else if (t.isFile() && t.getName().toLowerCase(Locale.ROOT).endsWith(".java")) {
                    rows += rows(t);
                    System.out.printf("%s(%d)[%3$tF %<tT]%n", t.getAbsolutePath(), rows(t), t.lastModified());
                    ++filecount;
                }
            }
        } else if (file.isFile() && file.getName().toLowerCase(Locale.ROOT).endsWith(".java")) {
            rows += rows(file);
            System.out.printf("%s(%d)[%3$tF %<tT]%n", file.getAbsolutePath(), rows(file), file.lastModified());
            ++filecount;
        }
    }

    public static long rows(File file) {
        long rows = 0;
        try {
            var br = new BufferedReader(new FileReader(file));
            rows = br.lines().count();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rows;
    }
}
